const { request } = require('./util')

// 模拟数据生成函数
const mockData = {
  // 生成模拟用户信息
  getUserInfo: () => {
    return {
      code: 200,
      data: {
        nickName: '测试用户',
        department: '财务部',
        avatar: '',
        mobile: '13800138000'
      }
    }
  },
  
  // 生成模拟凭证记录列表
  getVerifyRecords: () => {
    return {
      code: 200,
      data: {
        total: 5,
        list: [
          {
            id: '001',
            receiptType: '增值税发票',
            status: '1', // 鉴定完成
            uploadTime: new Date().getTime() - 86400000, // 一天前
            description: '差旅费发票',
            result: 'pass'
          },
          {
            id: '002',
            receiptType: '火车票',
            status: '1', // 鉴定完成
            uploadTime: new Date().getTime() - 172800000, // 两天前
            description: '出差火车票',
            result: 'fail'
          },
          {
            id: '003',
            receiptType: '普通发票',
            status: '0', // 鉴定中
            uploadTime: new Date().getTime() - 3600000, // 一小时前
            description: '办公用品'
          }
        ]
      }
    }
  },
  
  // 生成模拟报告详情
  getVerifyReport: (id) => {
    const reports = {
      '001': {
        id: '001',
        receiptType: '增值税发票',
        status: '1', // 鉴定完成
        uploadTime: new Date().getTime() - 86400000, // 一天前
        description: '差旅费发票',
        result: 'pass',
        images: ['/static/images/receipt-sample.jpg'],
        reason: '发票真实有效，符合报销要求'
      },
      '002': {
        id: '002',
        receiptType: '火车票',
        status: '1', // 鉴定完成
        uploadTime: new Date().getTime() - 172800000, // 两天前
        description: '出差火车票',
        result: 'fail',
        images: ['/static/images/receipt-sample.jpg'],
        reason: '票据信息不完整，无法验证真实性'
      },
      '003': {
        id: '003',
        receiptType: '普通发票',
        status: '0', // 鉴定中
        uploadTime: new Date().getTime() - 3600000, // 一小时前
        description: '办公用品',
        images: ['/static/images/receipt-sample.jpg']
      }
    }
    
    return {
      code: 200,
      data: reports[id] || reports['001']
    }
  }
}

// 用户相关接口
const userApi = {
  // 登录
  login: (data) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: {
            token: 'mock-token-123456',
            userInfo: {
              nickName: data.mobile ? '手机用户' : '微信用户',
              department: '财务部',
              avatar: ''
            }
          }
        })
      }, 500)
    })
  },
  
  // 获取用户信息
  getUserInfo: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(mockData.getUserInfo())
      }, 500)
    })
  },
  
  // 更新用户信息
  updateUserInfo: (data) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          message: '更新成功'
        })
      }, 500)
    })
  }
}

// 公车相关接口
const carApi = {
  // 获取公车列表
  getCarList: (data) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: {
            list: [],
            total: 0
          }
        })
      }, 500)
    })
  },
  
  // 获取公车详情
  getCarDetail: () => Promise.resolve({code: 200, data: {}}),
  
  // 提交用车申请
  applyUseCar: () => Promise.resolve({code: 200, message: '申请成功'}),
  
  // 获取用车记录
  getUseRecords: () => Promise.resolve({code: 200, data: {list: [], total: 0}})
}

// 报销相关接口
const receiptApi = {
  // 上传报销凭证
  uploadReceipt: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          message: '上传成功',
          data: {
            id: new Date().getTime().toString()
          }
        })
      }, 800)
    })
  },
  
  // 获取报销记录
  getReceiptList: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: {
            list: [],
            total: 0
          }
        })
      }, 500)
    })
  },
  
  // 获取报销详情
  getReceiptDetail: () => Promise.resolve({code: 200, data: {}}),
  
  // 提交报销申请
  applyReimbursement: () => Promise.resolve({code: 200, message: '申请成功'}),
  
  // 上传报销凭证进行鉴别
  uploadForVerify: (data) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          message: '上传成功',
          data: {
            id: new Date().getTime().toString()
          }
        })
      }, 800)
    })
  },
  
  // 获取鉴别记录列表
  getVerifyRecords: () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(mockData.getVerifyRecords())
      }, 500)
    })
  },
  
  // 获取鉴别报告详情
  getVerifyReport: (id) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(mockData.getVerifyReport(id))
      }, 500)
    })
  },
  
  // 下载鉴别报告
  downloadReport: (data) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({
          statusCode: 200,
          tempFilePath: 'mock-file-path'
        })
      }, 1000)
    })
  }
}

// 文件上传
const uploadFile = (filePath, formData = {}) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        code: 200,
        message: '上传成功',
        data: {
          url: filePath // 直接返回本地路径作为模拟
        }
      })
    }, 1000)
  })
}

module.exports = {
  user: userApi,
  car: carApi,
  receipt: receiptApi,
  uploadFile
} 